var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
o.BezierPart = void 0;
var r = cc._decorator,
    s = r.ccclass,
    c = r.property,
    p = (r.menu, r.executeInEditMode),
    l = (function () {
        function t(t, e, o, a) {
            this.posArray = [];
            this.lenght = null;
            this.startPos = t;
            this.cPos1 = e;
            this.cPos2 = o;
            this.endPos = a;
            this.lenght = this.getBezierLen();
        }
        t.prototype.createPosArray = function (t) {
            for (var e = Math.floor(this.lenght / t), o = 1 / e, a = o; a <= 1; a += o) {
                var i = this.bezier(this.startPos.x, this.cPos1.x, this.cPos2.x, this.endPos.x, a),
                    n = this.bezier(this.startPos.y, this.cPos1.y, this.cPos2.y, this.endPos.y, a);
                this.posArray.push(cc.v2(i, n));
            }
            this.posArray.length < e && this.posArray.push(this.endPos);
        };
        t.prototype.getBezierLen = function (t) {
            void 0 === t && (t = 20);
            var e,
                o,
                a = 0,
                i = cc.v2(0, 0);
            for (e = 0; e <= 1; e += 0.05) {
                var n = this.bezier(this.startPos.x, this.cPos1.x, this.cPos2.x, this.endPos.x, e),
                    r = this.bezier(this.startPos.y, this.cPos1.y, this.cPos2.y, this.endPos.y, e);
                a += (o = cc.v2(n, r)).sub(i).mag();
                i = o;
            }
            return a;
        };
        t.prototype.bezier = function (t, e, o, a, i) {
            return (
                t * Math.pow(1 - i, 3) + 3 * e * i * Math.pow(1 - i, 2) + 3 * o * i * i * (1 - i) + a * Math.pow(i, 3)
            );
        };
        return t;
    })();
o.BezierPart = l;
var d = (function (t) {
    i(e, t);
    function e() {
        var e = (null !== t && t.apply(this, arguments)) || this;
        e.list = [];
        e.movePosBean = new l(cc.v2(0, 0), cc.v2(50, 50), cc.v2(60, 50), cc.v2(120, 0));
        e.dirIndex = "1";
        return e;
    }
    e.prototype.onLoad = function () {
        this.resetClear();
    };
    e.prototype.drawPath = function () {};
    e.prototype.creatNewPos = function () {
        this.resetClear();
    };
    e.prototype.upataPos = function () {
        for (var t = [], e = 0; e < this.list.length; e++) t.push(cc.v2(this.list[e].position));
        return t;
    };
    e.prototype.resetClear = function () {
        if (this.list.length >= 3) {
            this.movePosBean.posArray.length = 0;
            for (var t = 0; t < this.list.length - 2; t += 2) {
                this.movePosBean.startPos = cc.v2(this.list[t + 0].position);
                this.movePosBean.cPos1 = cc.v2(this.list[t + 1].position);
                this.movePosBean.cPos2 = cc.v2(this.list[t + 1].position);
                this.movePosBean.endPos = cc.v2(this.list[t + 2].position);
                this.movePosBean.createPosArray(5);
            }
            this.drawPath(this.movePosBean.posArray);
        }
    };
    e.prototype.setNode = function () {};
    n([c([cc.Node])], e.prototype, "list", void 0);
    n([c()], e.prototype, "dirIndex", void 0);
    return n([s, p], e);
})(cc.Component);
o.default = d;
